package com.lq.controller;

import com.lq.pojo.Category;
import com.lq.pojo.Tag;
import com.lq.pojo.User;
import com.lq.service.CategoryService;
import com.lq.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class TagController {

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private TagService tagService;

    @RequestMapping("/getTag")
    public String showCategoryAndTagServlet(HttpSession session, Model model) {

        User user = (User) session.getAttribute("user");

        List<Category> categoryList = categoryService.getAllCategory();

        List<Tag> tagList = tagService.getAllTag(user.getUserId());

        model.addAttribute("categoryList", categoryList);
        model.addAttribute("tagList", tagList);

        return "tag";
    }
}
